/*
 * strParser.h
 *
 *  Created on: 25.04.2014
 *      Author: gsemmler1
 */

#ifndef STRPARSER_H_
#define STRPARSER_H_

#include <iostream>
#include <istream>

#include <string>
#include <vector>

#include <boost/shared_ptr.hpp>

#include <Parsers/IParsingActions.h>

#include <Parsers/GrammarRawStructs.h>
#include <Parsers/Color.h>
#include <Parsers/SurpacStyleContainer.h>
namespace GST
{
namespace Parsers
{
class StrParser
{
	enum ParserState
	{
		UNDEFIEND, HEAD, NEW_PART, NORMAL_PARSE
	};

	enum AddBehavior
	{
		ADD_POINT, NEW_SIMPLEX, NEW_LINE,
	};
	struct strVertex
	{
		AddBehavior add;
		GST::Parsers::RawPoint3 point;
		std::vector<std::string> propertyList;
		GST::Parsers::Color color;
	};
	GST::Parsers::SurpacStyleContainer mStyle;
	const bool mMetaDataParse;

	double getDouble(const std::string& s);
	bool getVertex(ParserState parserState, int lastLineNumber, int lineNumber,
			std::vector<std::string>& parts, std::vector<strVertex>& vertexList,
			size_t& propertyCount, std::stringstream& part,
			const std::string& line, std::vector<std::string>& fileParts);
	bool parseFile(std::vector<strVertex>& vertexList, std::istream& file,
			size_t& propertyCount, std::string& name, std::string& head,
			std::vector<std::string>& fileParts);
	void createGeometry(GeometryTypes type,
			const boost::shared_ptr<IParsingActions>& actions,
			std::vector<std::string> parts, size_t& objCount, const std::string& name);

public:
	/**
	 * @param styles
	 *       the stylecontainer which should be used
	 * @param metaDataParse
	 *       should parsing be metadataparsing
	 *
	 */
	StrParser(const GST::Parsers::SurpacStyleContainer& styles,
			const bool metaDataParse) :
			mMetaDataParse(metaDataParse), mStyle(styles)
	{
	}
	/**
	 * Parse a str-File from a InputStream
	 * 
	 * @param strFile
	 *        the inputstream
	 * @param actions
	 *        the interface which should be used
	 * @param type
	 *        the geotype which should be parsed
	 */
	void parse(std::istream& strFile,
			boost::shared_ptr<IParsingActions> actions, GeometryTypes type);

};

}
}
#endif /* STRPARSER_H_ */
